package com.neuedu.controller;

import com.neuedu.bean.Food;
import com.neuedu.bean.User;
import com.neuedu.common.R;
import com.neuedu.mapper.UserMapper;
import com.neuedu.service.FoodService;
import com.neuedu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

// 1. 将该类转换控制器类，并设置该中的方法返回值全部都是json数据
//@Controller
//@ResponseBody
@RestController
// 2. 设置该模块的请求路径，如/user
@RequestMapping("/food")
// 3. 解决跨域
@CrossOrigin
public class FoodController {

    @Autowired
    private FoodService foodService;


    /**
     * 根据商家Id获取商家对应的菜品列表
     * @param businessId
     * @return
     */
    @GetMapping("/listFoodByBusinessId/{businessId}")
    public R getUserById(@PathVariable("businessId") Integer businessId){
        try {
            List<Food> foodList = foodService.listFoodByBusinessId(businessId);
            return R.ok().data(foodList);
        } catch (Exception e) {
            // 如果有异常，进行抛出异常。相当于该方法有返回值了。
            throw new RuntimeException(e);
        }

    }


}
